/*
 * quick view beans
 */
function ProductPageResp(){}
ProductPageResp.prototype.objectType=function(){return "ProductPageResp";};
var ProductPageResp_sizesForColorResp="sizesForColorResp";
var ProductPageResp_colorsForSizeResp="colorsForSizeResp";
var ProductPageResp_quickViewSuiteItemResp="quickViewSuiteItemResp";
var ProductPageResp_quickViewResp="quickViewResp";
var ProductPageResp_inventoryStatusResp="inventoryStatusResp";
var ProductPageResp_promoModalResp="promoModalResp";
var ProductPageResp_addToCartResp="addToCartResp";
var CheckoutResp_omnitureProperties = "omnitureProperties";		// array of OmnitureProperties

function QuickViewReq(){}
QuickViewReq.prototype.objectType=function(){return "QuickViewReq";};
var QuickViewReq_productId="productId";
var QuickViewReq_type="type";
var QuickViewReq_url="url";
var QuickViewReq_quickviewClass="quickviewClass";
var QuickViewReq_itemPos="itemPos";
var QuickViewReq_detailsOnly="detailsOnly";
var QuickViewReq_prodPageLink="prodPageLink";

function QuickViewResp(){}
QuickViewResp.prototype.objectType=function(){return "QuickViewResp";};
var QuickViewResp_html="html";
var QuickViewResp_prodPageLink="prodPageLink";

function ColorsForSizeReq(){}
ColorsForSizeReq.prototype.objectType=function(){return "ColorsForSizeReq";};
var ColorsForSizeReq_productId="productId";
var ColorsForSizeReq_size="size";
var ColorsForSizeReq_styleId="styleId";
var ColorsForSizeReq_selectedColor="selectedColor";

function ColorsForSizeResp(){}
ColorsForSizeResp.prototype.objectType=function(){return "ColorsForSizeResp";};
var ColorsForSizeResp_productId="productId";
var ColorsForSizeResp_colors="colors";
var ColorsForSizeResp_styleId="styleId";

function InventoryStatusReq(){}
InventoryStatusReq.prototype.objectType=function(){return "InventoryStatusReq";};
var InventoryStatusReq_productId="productId";
var InventoryStatusReq_size="size";
var InventoryStatusReq_color="color";

function InventoryStatusResp(){}
InventoryStatusResp.prototype.objectType=function(){return "InventoryStatusResp";};
var InventoryStatusResp_productId="productId";
var InventoryStatusResp_inventoryStatus="inventoryStatus";
var InventoryStatusResp_expectedMessage="expectedMessage";

function AddToCartReq(){}
AddToCartReq.prototype.objectType=function(){return "AddToCartReq";};
var AddToCartReq_productId="productId";
var AddToCartReq_size="size";
var AddToCartReq_color="color";
var AddToCartReq_qty="qty";
var AddToCartReq_suiteId="suiteId";

function AddToCartResp(){}
AddToCartResp.prototype.objectType=function(){return "AddToCartResp";};
var AddToCartResp_html="html";
var AddToCartResp_gwpHtml="gwpHtml"
	
function AddToCartGwpReq(){}
AddToCartGwpReq.prototype.objectType=function(){return "AddToCartGwpReq";};
var AddToCartGwpReq_productId="productId";
var AddToCartGwpReq_size="size";
var AddToCartGwpReq_color="color";
var AddToCartGwpReq_qty="qty";
var AddToCartGwpReq_promoKey="promoKey";

/*
 * quick view registration
 */
function QuickViewResp(eventObj, eventName, eventId, eventHandler){
	var id = ''; // let the process figure out what the content section is
	var html = eventObj.html;
	var detailsOnly = eventObj.detailsOnly;
	if(detailsOnly){
		quickview.updateQuickViewItemDetails(html);
	} else {
		quickview.jqueryAppend(id, html);
	}
}
NMEventManager.addEventListener("quickViewResp",QuickViewResp);

function ColorsForSizeResp(eventObj, eventName, eventId, eventHandler){
	var colors = eventObj.colors.string;
	if (colors != undefined){
		var productId = eventObj.productId;
		quickview.enableColors(productId, colors);
	}
}
NMEventManager.addEventListener("colorsForSizeResp",ColorsForSizeResp);

function InventoryStatusResp(eventObj, eventName, eventId, eventHandler){
	var productId = eventObj.productId;
	var inventoryStatus = eventObj.inventoryStatus;
	var expectedMessage = eventObj.expectedMessage;
	quickview.inventoryStatus(productId, inventoryStatus, expectedMessage);
}
NMEventManager.addEventListener("inventoryStatusResp",InventoryStatusResp);

function AddToCartResp(eventObj, eventName, eventId, eventHandler){
	var html = eventObj.html;
	var gwpHtml = eventObj.gwpHtml;
	objMiniCart.DisplayMiniCart(html);
	objCartLink.Populate();	
	//make sure the timer is not paused, then start the timer
	objMiniCart.Resume();

	if (gwpHtml != undefined){
		lightboxWindow.Populate(gwpHtml);
	}
	
	objTimer.Secs = allPagesMiniCartSecs;
	objTimer.ResetSecs = afterPauseMiniCartSecs;
	objTimer.Pause = objMiniCart.IsPause;
    objTimer.Finish = unloadMiniCart;
	objTimer.Start();
}
NMEventManager.addEventListener("addToCartResp",AddToCartResp);

/*
 * jquery objects for quick view
 */
quickview = (function($){
	function init() {
		initProductHover();
		initProductQuickview();
		initYuiMenu();
	}
	
	function initProductHover() {
		$('div.featureproduct').live('hover', function(ev){
			if(ev.type==='mouseover' || ev.type==='mouseenter') {
				var $this = $(this);
				$this.addClass('hover');
				var $featureOverlayBack = $this.find('div.featureOverlayBack');
				var $qvTip = $this.find('div.qv-tip');
				// reposition qv-tip
				$qvTip.offset({ top: $featureOverlayBack.offset().top-30, left: $featureOverlayBack.offset().left});
			}
			if(ev.type==='mouseout') {
				var $this = $(this);
				$this.removeClass('hover');
			}
		});
		$('div.products').find('div.product,div.productstart').live('hover', function(ev){
			if(ev.type==='mouseover' || ev.type==='mouseenter') {
				var $this = $(this);
				$this.addClass('hover');
			}
			if(ev.type==='mouseout') {
				var $this = $(this);
				$this.removeClass('hover');
			}
		});
		$('div.productSlot').find('div.product,div.productstart').live('hover', function(ev){
			if(ev.type==='mouseover' || ev.type==='mouseenter') {
				var $this = $(this);
				$this.addClass('hover');
			}
			if(ev.type==='mouseout') {
				var $this = $(this);
				$this.removeClass('hover');
			}
		});
	}
	
	function initProductQuickview(){
		var $container = getContentSection();
		$container.find('div.qv-tip').live('click',function(ev){
		//quickly close minicart if open before firing off new quicklook
		quickCloseMiniCart();
		updateQuickLook($(this));			
		});
	}
	
	//override yuimenu inline style 
	 function initYuiMenu(){ 
          $('li.yuimenubaritem').live('hover', function(ev){ 
               if(ev.type==='mouseover' || ev.type==='mouseenter') { 
                    var $target = $(ev.currentTarget) 
                    var $divchild = $target.children('div'); 
                    if($divchild.length > 0)
                    {
                    	$divchild.css('z-index','150');
                    } 
               } 
               if(ev.type==='mouseout') {} 
          }); 
     }
	
	function updateQuickLook($qvEL) {
		var productId = $qvEL.attr('product_id');
		if(productId != null && productId != ""){
			var quickViewReq = new QuickViewReq();
			quickViewReq[QuickViewReq_productId]=productId;
			quickViewReq[QuickViewReq_url]="/common/store/catalog/quickview/quickView.jhtml";
			quickViewReq[QuickViewReq_type]="";
			quickViewReq[QuickViewReq_quickviewClass]="";
			quickViewReq[QuickViewReq_itemPos]=1;
			// need to pass link to product page
			var $productDiv = $qvEL.parent();
			var $prodImgLink = $productDiv.find('a');
			var prodPageLink = $prodImgLink.attr('href');
			if(prodPageLink.indexOf("QuickToProduct") == -1){
				prodPageLink = prodPageLink + "&navid=QuickToProduct";
			}
			quickViewReq[QuickViewReq_prodPageLink]=prodPageLink;
			// make ajax call
			productGateway.ajaxService(quickViewReq,function(){displayQuickLook($qvEL);},null);
		}
	}

	function initQuickViewLinks($qv, productListFlag){
		resizeProductDescription();
		initQuickLookImageList($qv);
		if(productListFlag){
			initQuickLookProductList($qv);
		}
		initQuickLookColors($qv);
		initAddToCart($qv);
	}
	
	function displayQuickLook($qvEL){
		var divquickview = 'div.quickview';
		var $qv = $(divquickview);
		var $qvIframe = $('#quickviewIframe');

		/*what is the height of the active window*/
		var top = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
		top = top ? top : 0;
		if(top>100){
			top = top - 110;
		} else {
			top = top + 30;
		}
		
		$('#QV').css('top',top);
		// resize quick view by adding classes
		$quickViewSuiteProducts = $('#quickViewSuiteProducts');
		if($quickViewSuiteProducts.length > 0){
			$qv.addClass('suite');
			resizeSuite($qv);
		} else {
			$moreViews = $qv.find('div.moreViews');
			if($moreViews.length>0){
				$qv.addClass('qvAltImg');
			}
		}
		$qvIframe.css('height',$('#quickviewRd').outerHeight());

		$qv.find('div.close-x').one('click', function(){
			$('#QV').remove();
		});

		$('body').click(function(ev){
			var $target = $(ev.target);
			var isQuickview = $target.parents(divquickview);
			var isCartlinkspandiv = $target.parents('#cartlinkspandiv');
			if(isQuickview.length == 0 && isCartlinkspandiv.length  == 0){
				$('#QV').remove();
				$('body').unbind('click');
			}
		});
		
		// link clicks
		initQuickViewLinks($qv, true);
	}
	
	function initAddToCart($qv){
		$qv.find('input.addtobag').click(function(ev){
			var $this = $(this);
			var productId = $('#qvAddToCart').attr('product_id');
			var qty = $this.attr('qty');
			var $qvSize = $qv.find('select.qvSize[product_id='+productId+']');
			var $qvColor = $qv.find('select.qvColor[product_id='+productId+']');
			var suiteId = $qv.find('li.active').attr('product_id');
			
			var sizeSelected = "";
			var colorSelected = "";
			if($qvSize.length > 0){
				sizeSelected = $qvSize.find('option:selected').val();
				if(sizeSelected == ""){
					var displayName = $('#qvDesignerProduct').find('h1.displayName');
					alert('- Please choose a color and/or size for the product "' + displayName.text() + '".\n');
					return;
				}
			}
			if($qvColor.length > 0){
				colorSelected = $qvColor.find('option:selected').val();
				if(colorSelected == ""){
					var displayName = $('#qvDesignerProduct').find('h1.displayName');
					alert('- Please choose a color and/or size for the product "' + displayName.text() + '".\n');
					return;
				}
			}

			// define ajax request
			var addToCartReq = new AddToCartReq();
			addToCartReq[AddToCartReq_productId]=productId;
			addToCartReq[AddToCartReq_qty]=qty;
			addToCartReq[AddToCartReq_size]=sizeSelected;
			addToCartReq[AddToCartReq_color]=colorSelected;
			addToCartReq[AddToCartReq_suiteId]=suiteId;
			productGateway.ajaxService(addToCartReq,function(){changeAddImage($qv);},null);

			// simulate body click to close quickview if a regular product
			if(!$('div.quickview').hasClass('suite')){
				scroll(0,0); // to see mini cart if not on suite
				$('body').click();
			}

			// display mini cart
			objMiniCart.DisplayWait();
	
		});
	}

	/*
	 * change the add to bag image to added if it is a suite
	 * also reset the size/color to choose option
	 * make added image not clickable
	*/
	function changeAddImage($qv){
		if($qv.hasClass('suite')){
			var $qvAddToCart = $('#qvAddToCart');
			var addtobagInput = $qvAddToCart.find('input.addtobag');
			if(addtobagInput.length > 0){
				// must unbind (non clickable) before other steps
				addtobagInput.unbind('click');
				// now reset size/color
				var $size = $qv.find('select.qvSize');
				if($size.length > 0){
					$size.find('option:selected').attr('selected',false);
					$size.find('option[value=""]').attr('selected',true);
					$size.change();
				} else {
					var $color = $qv.find('select.qvColor');
					if($color.length > 0){
						$color.find('option:selected').attr('selected',false);
						$color.find('option[value=""]').attr('selected',true);
						$color.change();
					}
				}
				// now change the image to added and make default curser
				addtobagInput.attr('src','/category/quicklook/added.gif');
				$qvAddToCart.addClass('noClick');
			}
		}
	}
	
	/*
	 * This returns true if the add to cart image has been change to Added
	*/
	function isAddedImage(){
		var $qvAddToCart = $('#qvAddToCart');
		var addtobagInput = $qvAddToCart.find('input.addtobag');
		if(addtobagInput.length > 0){
			if(addtobagInput.attr('src') == '/category/quicklook/added.gif'){
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}
	
	/*
	 * this is used to change the suite Added image back to add to bag image
	 * also this allows the image to be clickable
	*/
	function changeAddToBagImage(){
		var $qvAddToCart = $('#qvAddToCart');
		var addtobagInput = $qvAddToCart.find('input.addtobag');
		if(addtobagInput.length > 0){
			$qvAddToCart.removeClass('noClick');
			addtobagInput.attr('src','/category/quicklook/addtoshoppingbag.gif');
			// make add to cart image clickable
			initAddToCart($('div.quickview'));
		}
	}
	
	function initQuickLookImageList($qv){
		$qvImage = $qv.find('div.qvImage');
		$qvImage.find('li').click(function(ev){
			var $this = $(this);
			// if the position was not defined do nothing
			var pos = $this.attr('pos');
			if(!pos){
				return;
			}
			// if the position was active do nothing
			if($this.hasClass('active') || $this.hasClass('prevdim') || $this.hasClass('nextdim')){
				return;
			}
			// remove previous active
			var $ul = $this.parent();
			var $active = $ul.find('li[class=active]');
			if($active.length > 0){
				$active.removeClass('active');
			}
			// if the url was not defined, find the li with the position and its' line number
			// add active to class
			var url = $this.attr('url');
			if(url){
				$this.addClass('active');
			} else {
				$line = $qvImage.find('li[pos="'+pos+'"][lineNum="true"]');
				url = $line.attr('url');
				$line.addClass('active');
			}
			$img = $qvImage.find('img.qvMainImage');
			$img.attr('src',url);
			// get prev and next
			$prev = $qvImage.find('li.prev,li.prevdim');
			$next = $qvImage.find('li.next,li.nextdim');
			//  change visibility of prev and next
			if(pos == '1'){
				$prev.removeClass('prev');
				$prev.addClass('prevdim');
				$next.removeClass('nextdim');
				$next.addClass('next');
			} else if (pos == $next.attr('max')){
				$next.removeClass('next');
				$next.addClass('nextdim');
				$prev.removeClass('prevdim');
				$prev.addClass('prev');
			} else {
				$next.removeClass('nextdim');
				$next.addClass('next');
				$prev.removeClass('prevdim');
				$prev.addClass('prev');
			}
			// set prev and next position values
			$prev.attr('pos',parseInt(pos)-1);
			$next.attr('pos',parseInt(pos)+1);
			// set omniture
			omnitureHandler.quickviewAltImageClick($ul.attr('catalog')+'_'+$ul.attr('item'));
		});
	}

	function initQuickLookProductList($qv){
		var $quickViewSuiteProducts = $('#quickViewSuiteProducts');
		var $ulsecond = $quickViewSuiteProducts.find('ul.second');
		if($ulsecond.length > 0){
			var $ulfirst = $quickViewSuiteProducts.find('ul.first');
			$ulfirst.css('width',$ulsecond.width());
		}
		
		var productType = $quickViewSuiteProducts.attr('productType');
		if(productType == "2"){
			// posible multiple columns
			$quickViewSuiteProducts.find('ul').each(function(){
				var $this = $(this);
				$this.addClass('noclick');
				$this.find('li.active').removeClass('active');
			});
		} else {
			var $suiteItems = $qv.find('div.suiteItems');
			$suiteItems.find('li').click(function(ev){
				var $this = $(this);
				// do not send request for active product
				if($this.hasClass('active')){
					return;
				}
				// do not send request for invalid products
				var productId = $this.attr('product_id');
				if(productId == null || productId == ""){
					return;
				}
				var itemPos = $this.attr('item_pos');
				if(itemPos == null){
					itemPos = "1";
				}
				// remove active class from previous product displayed
				var $active = $suiteItems.find('li[class=active]');
				if($active.length > 0){
					$active.removeClass('active');
				}
				// add active to class
				$this.addClass('active');
				// define ajax request
				var quickViewReq = new QuickViewReq();
				quickViewReq[QuickViewReq_productId]=productId;
				quickViewReq[QuickViewReq_url]="/common/store/catalog/quickview/frgQuickViewDetails.jhtml";
				quickViewReq[QuickViewReq_type]='';
				quickViewReq[QuickViewReq_quickviewClass]='';
				quickViewReq[QuickViewReq_itemPos]=itemPos;
				quickViewReq[QuickViewReq_detailsOnly]="true";
				// set the product page link
				var prodPageLink = $('#quickViewSuiteProducts').attr('prodPageLink');
				if(prodPageLink.indexOf("QuickToProduct") == -1){
					prodPageLink = prodPageLink + "&navid=QuickToProduct";
				}
				quickViewReq[QuickViewReq_prodPageLink]=prodPageLink;
				// on complete link clicks
				productGateway.ajaxService(quickViewReq,function(){initQuickViewLinks($qv, false);},null);
			});
		}
	}
	
	function initQuickLookColors($qv){
		var $details = $qv.find('div.details');
		var $size = $details.find('select.qvSize'); 
		var $color = $details.find('select.qvColor');
		var productId = $('#qvAddToCart').attr('product_id');
		if($size.length == 0 && $color.length == 0){
			inventoryStatusCheck($size, $color, productId);
		} else if($size.length == 0){
			var selectedColor = $color.find('option:selected').val()
			var colorsForSizeReq = new ColorsForSizeReq();
			colorsForSizeReq[ColorsForSizeReq_productId]=productId;
			colorsForSizeReq[ColorsForSizeReq_size]="";
			colorsForSizeReq[ColorsForSizeReq_styleId]="";
			colorsForSizeReq[ColorsForSizeReq_selectedColor]=selectedColor;
			productGateway.ajaxService(colorsForSizeReq,null,null);
			inventoryStatusCheck($size, $color, productId);
		} else {
			$size.change(function(ev){
				var $size = $(this);
				var productId = $size.attr('product_id');
				var sizeSelected = $size.find('option:selected').val();
				if(sizeSelected == ""){
					var $color = $size.siblings('select.qvColor');
					$color.empty();
					$color.append('<option value="">Then, Select Color</option>');
					inventoryStatus(productId, "", "");
				} else {
					var $color = $size.siblings('select.qvColor');
					var selectedColor = $color.find('option:selected').val()
					var styleId = "";
		
					var colorsForSizeReq = new ColorsForSizeReq();
					colorsForSizeReq[ColorsForSizeReq_productId]=productId;
					colorsForSizeReq[ColorsForSizeReq_size]=sizeSelected;
					colorsForSizeReq[ColorsForSizeReq_styleId]="";
					colorsForSizeReq[ColorsForSizeReq_selectedColor]=selectedColor;
					productGateway.ajaxService(colorsForSizeReq,null,null);
					inventoryStatusCheck($size, $color, productId);
				}
				if(isAddedImage()){
					changeAddToBagImage()
				}
			});
			$size.change();
		}
	}
	
	function enableColors(productId, colors){
		colors = convertTypeToStringInArray(colors);
		var $colorsEL = $('select.qvColor[product_id="'+productId+'"]');
		if($colorsEL.length>0) {
			var selectedColor = $colorsEL.find('option:selected').val();
			if(selectedColor == undefined){
				selectedColor = "";
			}
			$colorsEL.empty();
			var $size = $colorsEL.siblings('select.qvSize');
			if($size.length == 0){
				$colorsEL.append('<option value="">Select Color</option>');
			} else {
				$colorsEL.append('<option value="">Then, Select Color</option>');
			}
			for(pos=0;pos<colors.length;pos++){
				if(selectedColor == colors[pos] || colors.length == 1){
					$colorsEL.append('<option value="'+colors[pos]+'" selected>'+colors[pos]+'</option>')
					// color is known so check inventory status
					var $color = $colorsEL;
					var $size = $color.siblings('select.qvSize');
					var productId = $color.attr('product_id');
					inventoryStatusCheck($size, $color, productId);
				} else {
					$colorsEL.append('<option value="'+colors[pos]+'">'+colors[pos]+'</option>')
				}
			}
			
			$colorsEL.change(function(ev){
				var $color = $(this);
				var $size = $color.siblings('select.qvSize');
				var productId = $color.attr('product_id');
				inventoryStatusCheck($size, $color, productId);
				if(isAddedImage()){
					changeAddToBagImage()
				}
			});
		}
	}
	
	function inventoryStatusCheck($size, $color, productId){
		var processFlag = true;
		var sizeVal = "";
		if($size.length > 0){
			sizeVal = $size.find(':selected').val();
			if(sizeVal == ""){
				processFlag = false;
			}
		}
		var colorVal = "";
		if($color.length > 0){
			if($color.length > 0){
				colorVal = $color.find(':selected').val();
				if(colorVal == ""){
					processFlag = false;
				}
			}
		}
		if(productId != undefined){
			if(processFlag){
				var inventoryStatusReq = new InventoryStatusReq();
				inventoryStatusReq[InventoryStatusReq_productId]=productId;
				inventoryStatusReq[InventoryStatusReq_size]=sizeVal;
				inventoryStatusReq[InventoryStatusReq_color]=colorVal;
				productGateway.ajaxService(inventoryStatusReq,null,null);
			} else {
				inventoryStatus(productId,"","");
			}
		}
	}
	
	function inventoryStatus(productId, inventoryStatus, inventoryDateMsg){
		if(inventoryDateMsg.length > 0){
			if(inventoryStatus.length > 0){
				inventoryStatus = inventoryStatus + "<br>" +  inventoryDateMsg;
			} else {
				inventoryStatus = inventoryDateMsg;
			}
		}
		document.getElementById(productId+"inventoryStatus").innerHTML = inventoryStatus;
	}
	
	function resizeProductDescription(){
		var $details = getContentSection().find('div.details');
		var $qvDesignerProduct = $('#qvDesignerProduct');
		var $qvMoreDesc = $('#qvMoreDesc');
		var $qvViewProductDetails = $('#qvViewProductDetails');
		var $qvPrice = $('#qvPrice');
		var $qvSizecolor = $('#qvSizecolor');
		var $qvAddToCart = $('#qvAddToCart');
		var $qvDescription = $('#qvDescription');
		
		var availableHeight = $details.outerHeight() - ($qvDesignerProduct.outerHeight() + $qvMoreDesc.outerHeight() + $qvViewProductDetails.outerHeight() + $qvPrice.outerHeight() + $qvAddToCart.outerHeight());
		if($qvSizecolor.length>0){
			availableHeight = parseInt(availableHeight) - $qvSizecolor.outerHeight();
		}
		// need to change height to auto to determine the actual height if everything was displayed.
		// starting height needed to be 0 so that div.details would calculate the correct height on ie6
		$qvDescription.css('height','auto');
		var descHeight = $qvDescription.outerHeight();

		if(parseInt(descHeight) > parseInt(availableHeight)){
			availableHeight = parseInt(availableHeight) - (parseInt(availableHeight) % 14);
			$qvDescription.css('height',availableHeight);
			$('#qvMoreDesc').css('visibility','visible');
		}
	}
	
	function resizeSuite($qv){
		var quickViewItemDetailsHeight = $('#quickViewItemDetails').height();
		var $quickViewSuiteProducts = $('#quickViewSuiteProducts');
		
		var quickViewSuiteProductsHeight = $quickViewSuiteProducts.find('div.suiteItemsText').outerHeight();
		var suiteImageHeight = $quickViewSuiteProducts.find('div.suiteImage').outerHeight();
		var suiteItemsHeight = $quickViewSuiteProducts.find('div.suiteItems').outerHeight();
		if(parseInt(suiteImageHeight) > parseInt(suiteItemsHeight)){
			quickViewSuiteProductsHeight = parseInt(quickViewSuiteProductsHeight) + parseInt(suiteImageHeight); 
		} else {
			quickViewSuiteProductsHeight = parseInt(quickViewSuiteProductsHeight) + parseInt(suiteItemsHeight);
		}
		
		var quickViewHeight = parseInt(quickViewItemDetailsHeight) + parseInt(quickViewSuiteProductsHeight);
		// reset css heights
		$quickViewSuiteProducts.css('height',quickViewSuiteProductsHeight);
		var $wrap = $qv.find('div.wrap');
		$wrap.css('height',quickViewHeight);
		$qv.css('height',$wrap.outerHeight());
	}

	function convertTypeToStringInArray(theArray){
		for(var pos=0;pos<theArray.length;pos++){
			var val = theArray[pos];
			if(typeof val != 'string'){
				theArray[pos] = val+"";
			}
		}
		return theArray;
	}
	
	function updateQuickViewItemDetails(html){
		$('#quickViewItemDetails').html(html);
	}
	
	function jqueryAppend(id, html, attr){
		var newDiv = document.createElement('div');
		
		if (attr == undefined){
			attr = "QV";	
		} 
		
		newDiv.setAttribute('id', attr);
		newDiv.innerHTML = html;
		if(id == ""){
			var $container = $('#content');
			if($container.length > 0){
				document.getElementById('content').appendChild(newDiv);
			} else {
				$container = $('#searchcontent');
				if($container.length > 0){
					document.getElementById('searchcontent').appendChild(newDiv);
				} 
			}
		} else {
			document.getElementById(id).appendChild(newDiv);
		}
	}
	
	function getContentSection(){
		var $container = $('#content');
		if($container.length == 0){
			$container = $('#searchcontent');
		} 
		return $container;
	}
	
	/*
	 *GWP submit
	*/
	function gwpSubmit(){
		//close any existing minicarts
		objMiniCart.HideMiniCart();
	
		//find choices
		var $container = $('#lightboxContent');
		var $gwpSize = $container.find('select.choice1');
		var $gwpColor = $container.find('select.choice2');
		
		//retrieve product_id
		var productIdTemp = $container.find('select.choice1').attr('id');
		var prodIdIndex = productIdTemp.lastIndexOf("_") + 1;
		var gwpProductId =productIdTemp.substr(prodIdIndex); 
		
		//retrieve size
		var gwpSizeSelected = $gwpSize.find('option:selected').text();
		//retrieve color
		var gwpColorSelected = $gwpColor.find('option:selected').text();
		// set qty - always 1 for gwp
		var gwpQty = 1;
			
		var addToCartGwpReq = new AddToCartGwpReq();
		addToCartGwpReq[AddToCartGwpReq_productId]=gwpProductId;
		addToCartGwpReq[AddToCartGwpReq_qty]=gwpQty;
		addToCartGwpReq[AddToCartGwpReq_size]=gwpSizeSelected;
		addToCartGwpReq[AddToCartGwpReq_color]=gwpColorSelected;
		addToCartGwpReq[AddToCartGwpReq_promoKey]=gwpMultiSkuSelector.promoKey;
		productGateway.ajaxService(addToCartGwpReq,null,null);

		// display mini cart
		objMiniCart.DisplayWait();

		//remove lightbox
		lightboxWindow.Close();
		
	}
	
	return {
		init: init,
		jqueryAppend: jqueryAppend,
		updateQuickViewItemDetails: updateQuickViewItemDetails,
		enableColors: enableColors,
		inventoryStatus: inventoryStatus,
		gwpSubmit: gwpSubmit
	};
})(jQuery.noConflict());
jQuery(quickview.init);
